<template>
  <div>
    <div class="title">
      <hr>
      <div>
        <img src="../assets/logo.png"
             alt="">
        <span>商品列表</span>
      </div>
      <hr>
    </div>
    <div class="list">
      <div class="list_one"
           v-for="item in goodsList"
           :key="item.id"
           @click="turnInfo(item.id)">
        <img :src="item.pic"
             alt="">
        <div class="pname">
          {{item.name}} {{item.characteristic}}
        </div>
        <div class="price">
          <span>{{item.minPrice}}</span><del>{{item.originalPrice}}</del>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getDoodsApi } from '../api/home'
export default {
  name: 'Ljfvue2011Product',
  data () {
    return {
      goodsList: []
    };
  },
  created () {
    getDoodsApi().then(res => {
      console.log(res)
      if (res.data.code == 0) {
        this.goodsList = res.data.data;
      }
    })
  },
  mounted () {

  },

  methods: {
    // 跳转详情页并传参
    turnInfo (id) {
      this.$router.push({ name: "info", query: { pid: id } })
    }
  },
};
</script>

<style lang="less" scoped>
.title {
  hr {
    width: 40%;
  }
  display: flex;
  height: 60px;
  align-items: center;
  justify-content: space-around;
  background: white;
  margin-top: 10px;
  img {
    width: 50px;
    height: 50px;
    vertical-align: middle;
  }
}
.list {
  padding-bottom: 120px;
  width: 100%;
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  .list_one {
    width: 45%;
    background: white;
    height: 280px;
    text-align: left;
    font-size: 20px;
    margin-top: 10px;

    .pname {
      padding: 0 20px;
      box-sizing: border-box;
      height: 50px;
      // 多行省略号
      text-overflow: ellipsis;
      overflow: hidden;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    .price {
      padding: 0 20px;
      box-sizing: border-box;
      span {
        color: red;
        margin-right: 30px;
      }
    }
    img {
      width: 100%;
      height: 190px;
    }
  }
  //最后
  .list_one:last-child {
    margin-right: 50%;
  }
}
</style>